package com.ctshk.sapp.airexpress.controller;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.enums.SystemError;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.airexpress.dto.*;
import com.ctshk.rpc.airexpress.req.AirportExpressPageReq;
import com.ctshk.rpc.airexpress.req.AirportExpressUpdateBatchReq;
import com.ctshk.rpc.airexpress.req.AirportExpressUpdateReq;
import com.ctshk.rpc.airexpress.req.AirportExpressUpdateSaleStatusReq;
import com.ctshk.rpc.airexpress.service.IAirportExpressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(value = "机场快线管理", tags = "机场快线管理")
@RestController
@RequestMapping("/airport/express")
public class AirportExpressController extends BaseController {

    @DubboReference
    private IAirportExpressService airportExpressService;

    @ApiOperation(value = "机场快线-资源中心-产品管理列表", notes = "机场快线-资源中心-产品管理列表)")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "机场快线-资源中心-产品管理列表", operDesc = "机场快线-资源中心-产品管理列表")
    @GetMapping("/resource/list")
    public Result<List<AirportExpressDTO>> getResourceList() {
        return airportExpressService.selectResourceList();
    }

    @ApiOperation(value = "机场快线-产品中心-产品管理列表", notes = "机场快线-产品中心-产品管理列表)")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "机场快线-产品中心-产品管理列表", operDesc = "机场快线-产品中心-产品管理列表")
    @GetMapping("/product/list")
    public Result<List<AirportExpressDTO>> getProductList() {
        return airportExpressService.selectProductList();
    }

    @ApiOperation(value = "机场快线-预订中心-产品列表", notes = "机场快线-预订中心-产品列表)")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "机场快线-预订中心-产品列表", operDesc = "机场快线-预订中心-产品列表")
    @GetMapping("/reservation/list")
    public Result<List<AirportExpressReservationDTO>> getReservationList() {
        Long userId = getCurrentUser(getRequest()).getId();
        return airportExpressService.selectReservationList(userId);
    }

    @ApiOperation(value = "机场快线-预订中心-代理列表(模糊查询)", notes = "机场快线-预订中心-代理列表(模糊查询)")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "机场快线-预订中心-代理列表(模糊查询)", operDesc = "机场快线-预订中心-代理列表(模糊查询)")
    @GetMapping("/reservation/agent/list/{id}")
    public Result<List<AirportExpressReservationAgentDTO>> getReservationAgentListById(@PathVariable("id") Long id) {
        return airportExpressService.selectReservationAgentListById(id);
    }

    @ApiOperation(value = "机场快线-资源中心-产品信息", notes = "机场快线-资源中心-产品信息)")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "机场快线-资源中心-产品信息", operDesc = "机场快线-资源中心-产品信息")
    @GetMapping("/info/{id}")
    public Result<AirportExpressInfoDTO> getInfo(@PathVariable("id") Long id) {
        return Result.success(airportExpressService.selectInfo(id));
    }

    @ApiOperation(value = "机场快线-产品中心-产品详细", notes = "机场快线-产品中心-产品详细)")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "机场快线-产品中心-产品详细", operDesc = "机场快线-产品中心-产品详细")
    @GetMapping("/detail/{id}")
    public Result<AirportExpressInfoDTO> getDetail(@PathVariable("id") Long id) {
        return airportExpressService.selectDetail(id);
    }

    @ApiOperation(value = "机场快线-批量更新", notes = "机场快线-批量更新")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "机场快线-批量更新", operDesc = "机场快线-批量更新")
    @PutMapping("/update/batch")
    public Result updateBatchSaleStatus(@RequestBody @Valid AirportExpressUpdateBatchReq airportExpressUpdateBatchReq) {
        Long userId = getCurrentUser(getRequest()).getId();
        return airportExpressService.updateBatch(airportExpressUpdateBatchReq, userId);
    }


    @ApiOperation(value = "机场快线-更新API设置", notes = "机场快线-更新API设置")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "机场快线-更新API设置", operDesc = "机场快线-更新API设置")
    @PutMapping("/update")
    public Result update(@RequestBody @Valid AirportExpressUpdateReq airportExpressUpdateChargePriceReq) {
        Long userId = getCurrentUser(getRequest()).getId();
        return airportExpressService.update(airportExpressUpdateChargePriceReq, userId);
    }

    @ApiOperation(value = "机场快线-更新上架状态", notes = "机场快线-更新上架状态")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "机场快线-更新上架状态", operDesc = "机场快线-更新上架状态")
    @PutMapping("/update/sale/status")
    public Result updateBatchSaleStatus(@RequestBody @Valid AirportExpressUpdateSaleStatusReq airportExpressUpdateSaleStatusReq) {
        Long userId = getCurrentUser(getRequest()).getId();
        return airportExpressService.updateSaleStatus(airportExpressUpdateSaleStatusReq, userId);
    }

    @ApiOperation(value = "机场快线-分页查询列表", notes = "机场快线-分页查询列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "机场快线-分页查询列表", operDesc = "机场快线-分页查询列表")
    @GetMapping("/page")
    public Result<PageResponse<AirportExpressPageDTO>> getPage(@RequestBody @Valid AirportExpressPageReq airportExpressPageReq) {
        PageResponse<AirportExpressPageDTO> page = airportExpressService.getPage(airportExpressPageReq);
        return Result.success(page);
    }

    @ApiOperation(value = "机场快线-查询列表", notes = "机场快线-查询列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "机场快线-查询列表", operDesc = "机场快线-查询列表")
    @GetMapping("/list")
    public Result<List<AirportExpressDTO>> getList(@RequestBody List<Long> ids) {
        if(CollectionUtils.isEmpty(ids)){
            Result.failed(SystemError.SYS_402);
        }
        List<AirportExpressDTO> listByIds = airportExpressService.getListByIds(ids);
        return Result.success(listByIds);
    }
}